#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    FILE *fd = fopen("./bite.txt","w+");
    if(fd == NULL)
    {
        perror("fopen error");
        return 0;
    }

    const char *data = "linux so easy!";
    size_t len = strlen(data);
    size_t written = fwrite(data, 1, len, fd);
    if(written != len)
    {
        perror("fwrite error");
        fclose(fd);
        return 0;
    }
    
    fseek(fd,0, SEEK_SET);

    char buffer[50];
    size_t read = fread(buffer, 1, len ,fd);
    if(read != len)
    {
        perror("fread error");
        return 0; 
    }
    else
    {
        buffer[len] = '\0';
        printf("读取内容：%s\n", buffer);
    }

    fclose(fd);
    return 0;
}

